#include <iostream>
#include <string>
#include <regex>
using namespace std;

int main1() {
    string fnames[] = {"foo.txt", "bar.txt", "test", "a0.txt", "AAA.txt"};
    regex txt_regex("[a-z]+\\.txt");
    for (const auto &fname: fnames)
        cout << fname << ": " << regex_match(fname, txt_regex) << endl;

    return 0;
}

int main(){
    string s = "ab  aSa ** AA  (cc";
    regex pattern("[a-zA-Z]+");
    smatch result;
    string::const_iterator from = s.begin();
    string::const_iterator to = s.end();
    while(regex_search(from, to, result, pattern)){
        cout << result[0] << endl;
        from = result[0].second;
    }
    return 0;
}
